Completed
Push — master ( 8967bc...e88c19 )
by Rain
02:47
created

Script.js ➔ ... ➔ ???   D

Complexity

Conditions 10
Paths 11

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
c 1
b 0
f 0
nc 11
nop 1
dl 0
loc 26
rs 4.8196

How to fix   Complexity   

Complexity

Complex classes like Script.js ➔ ... ➔ ??? often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
2
import $ from '$';
3
import {AbstractComponent, componentExportHelper} from 'Component/Abstract';
4
5
class ScriptComponent extends AbstractComponent
6
{
7
	/**
8
	 * @constructor
9
	 * @param {Object} params
10
	 */
11
	constructor(params) {
12
13
		super();
14
15
		if (params.component && params.component.templateNodes && params.element &&
16
			params.element[0] && params.element[0].outerHTML)
17
		{
18
			let script = params.element[0].outerHTML;
19
			script = !script ? '' : script
20
				.replace(/<x-script/i, '<script')
21
				.replace(/<b><\/b><\/x-script>/i, '</script>');
22
23
			if (script)
24
			{
25
				params.element.text('');
26
				params.element.replaceWith(
27
					$(script).text(params.component.templateNodes[0] &&
28
						params.component.templateNodes[0].nodeValue ?
29
							params.component.templateNodes[0].nodeValue : ''));
30
			}
31
			else
32
			{
33
				params.element.remove();
34
			}
35
		}
36
	}
37
}
38
39
module.exports = componentExportHelper(ScriptComponent, 'ScriptComponent');
40